<?php

namespace console\models;

use app\api\core\wechat\wxAction;
use console\core\wechat\wxAnalysis;

class MainModel extends BaseModel
{
    /**
     * 统计所有的
     */
    public function actionSyncAll($appid='')
    {
        if (!empty($appid)) {
            $this->actionArticle($appid);
            $this->actionMsg($appid);
        } else {
            $this->wxAccount = [[
                'id'=>"6aea80ad7a90979c229067f9df0b7b9a",
                'accountappid'=>"wx2c076b140ffffb59"
            ]];
            if (!empty($this->wxAccount) && is_array($this->wxAccount)) {
                foreach ($this->wxAccount as $row) {
                    $this->actionArticle($row['accountappid']);
                    $this->actionMsg($row['accountappid']);
                }
            }
        }

        return true;
    }
    /**
     * 同步粉丝分析数据
     * @param $appid
     * @return bool
     */
    public  function actionUser($appid)
    {
        if (empty($appid)) return false;
        $wechat = new wxAnalysis();
        return $wechat->analysisUser($appid);
    }

    public function actionArticle($appid)
    {
        if (empty($appid)) return false;
        $wechat = new wxAnalysis();


        return $wechat->analysisArticle($appid);
    }

    public function actionMsg($appid)
    {
        if (empty($appid)) return false;
        $wechat = new wxAnalysis();

        return $wechat->analysisMsg($appid);
    }

    /**
     * 对公众号API及其后台清零操作
     * @param $appid
     */
    public function actionClearQuota($appid)
    {
        if (empty($appid)) return false;
        $wechat = new wxAction();
        return $wechat->setClearQuota($appid);
    }

    /**
     * 对开放平台的API清零操作
     */
    public function actionClearComponent()
    {
        if (empty($appid)) return false;
        $wechat = new wxAction();
        return $wechat->setClearQuotaComponent();
    }
}